<template>
  <div class="collect">
    <div class="top">
      <!-- 顶部导航栏 -->
      <van-nav-bar>
        <template #title>
          收藏/历史
        </template>
        <template #left>
          <div class="myicon" @click="back"><van-icon name="arrow-left" /></div
        ></template>
      </van-nav-bar>
    </div>
    <div class="showcollect">
      <van-tabs v-model="active" color="#3296fa">
        <van-tab title="我的收藏">
          <div
            class="content"
            v-for="(val, index) in collect"
            :key="index"
            @click="articleList(val.art_id)"
          >
            <div class="top">
              <h4>{{ val.title }}</h4>
            </div>
            <div class="middle">
              <div>{{ val.aut_name }}</div>
              <div>{{ val.comm_count }}评论</div>
              <div>{{ val.pubdate | mydayjstime }}</div>
            </div>
            <div class="bottom">
              <div class="item">
                <span><van-icon name="comment-o" size="16"/></span>
                <span>评论</span>
              </div>
              <div class="item">
                <span><van-icon name="like-o" size="16"/></span>
                <span>点赞</span>
              </div>
              <div>
                <span><van-icon name="share-o" size="16"/></span>
                <span>分享</span>
              </div>
            </div>
          </div>
        </van-tab>
        <van-tab title="我的历史">
          <div class="content" v-for="(val, index) in 5" :key="index">
            <div class="top">
              <h4>不想吃食堂，晚饭吃什么？</h4>
            </div>
            <div class="middle">
              <div>有点666</div>
              <div>4评论</div>
              <div>7个月前</div>
            </div>
            <div class="bottom">
              <div class="item">
                <span><van-icon name="comment-o" size="16"/></span>
                <span>评论</span>
              </div>
              <div class="item">
                <span><van-icon name="like-o" size="16"/></span>
                <span>点赞</span>
              </div>
              <div>
                <span><van-icon name="share-o" size="16"/></span>
                <span>分享</span>
              </div>
            </div>
          </div>
        </van-tab>
      </van-tabs>
    </div>
  </div>
</template>

<script>
import { getUserCollectionList } from '../../../api/news'
export default {
  data () {
    return {
      active: '',
      // 收藏的数据
      collect: []
    }
  },
  methods: {
    back () {
      this.$router.back()
    },
    // 去到文章的详情页面
    articleList (id) {
      this.$router.push(`/articleDetail/${id}`)
    }
  },
  async created () {
    this.active = +this.$route.params.active
    const res = await getUserCollectionList()
    console.log(res)
    this.collect = res.data.data.results
  }
}
</script>

<style lang="less" scoped>
.collect {
  background-color: #f5f7f9;
  height: 100vh;
  .top {
    /deep/ .van-nav-bar__content {
      background-color: #3296fa;
    }
    /deep/ .van-nav-bar__title.van-ellipsis {
      color: #fff;
    }
    .myicon {
      /deep/ i.van-icon.van-icon-arrow-left {
        color: #fff;
        font-size: 26px;
      }
    }
  }
  .showcollect {
    background-color: #fff;
    .content {
      margin-top: 20px;
      .top {
        padding: 0 15px;
        h4 {
          font-size: 16px;
          font-weight: normal;
        }
      }
      .middle {
        display: flex;
        padding: 0 15px;
        margin-top: 15px;
        font-size: 14px;
        color: #999999;
        div {
          margin-right: 8px;
        }
      }
      .bottom {
        display: flex;
        margin-top: 10px;
        border-top: 1px solid #f2f2f2;
        border-bottom: 1px solid #f2f2f2;
        width: 100%;

        div {
          flex: 1;
          font-size: 14px;
          height: 40px;
          line-height: 40px;
          text-align: center;
        }
        .item {
          border-right: 1px solid #f2f2f2;
        }
      }
    }
  }
}
</style>
